﻿<template>
  <a-modal
    :title="title"
    width="60%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="通道名称" prop="bankname">
          <a-input v-model="entity.bankname" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="通道代码" prop="bankcodenum">
          <a-input v-model="entity.bankcodenum" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="单笔限额" prop="PayMaxAmount">
          <a-input v-model="entity.PayMaxAmount" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="单日限额" prop="DayPayMaxAmount">
          <a-input v-model="entity.DayPayMaxAmount" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="单月限额" prop="MonthPayMaxAmount">
          <a-input v-model="entity.MonthPayMaxAmount" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="单笔最低金额" prop="UnderPayAmount">
          <a-input v-model="entity.UnderPayAmount" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="单笔低于最低金额手续费" prop="fee">
          <a-input v-model="entity.fee" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="是否启用" prop="isVisible">
          <a-radio-group default-value="1" button-style="solid" v-model="entity.isVisible">
            <a-radio-button :value="1">
            启用
            </a-radio-button>
            <a-radio-button :value="0">
            停用
            </a-radio-button>
          </a-radio-group>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {
        bankname:[{ required: true, message: '请输入通道名称' }],
        bankcodenum:[{ required: true, message: '请输入通道代码' }],
        PayMaxAmount:[{ required: true, message: '请输入单笔限额' }],
        DayPayMaxAmount:[{ required: true, message: '请输入单日限额' }],
        MonthPayMaxAmount:[{ required: true, message: '请输入单月限额' }],
        UnderPayAmount:[{ required: true, message: '请输入单笔最低金额' }],
        fee:[{ required: true, message: '请输入手续费' }],
      },
      title: ''
    }
  },
  methods: {
    init() {
      this.title = "新增";
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()

      if (id) {
        this.title = "修改";
        this.loading = true
        this.$http.post('/Base_bankcode/bankcode/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Base_bankcode/bankcode/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
